package com.yuwei.main

import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.yuwei.base.BaseViewActivity
import com.yuwei.common.entity.MyTab
import com.yuwei.common.path.RouterPath
import com.yuwei.main.adapter.MyFragmentAdapter
import com.yuwei.main.databinding.ActivityMainBinding
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
@Route(path = RouterPath.MODULE_MAIN_ACTIVITY)
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    val list = mutableListOf<Fragment>()
    lateinit var fragmentAdapter: MyFragmentAdapter
    override fun initView() {
        list.add(ARouter.getInstance().build(RouterPath.MODULE_HOME_FRAGMENT).navigation() as Fragment)
        list.add(ARouter.getInstance().build(RouterPath.MODULE_SERVICE_FRAGMENT).navigation() as Fragment)
        list.add(ARouter.getInstance().build(RouterPath.MODULE_MESSAGE_FRAGMENT).navigation() as Fragment)
        list.add(ARouter.getInstance().build(RouterPath.MODULE_NOTICE_FRAGMENT).navigation() as Fragment)
        list.add(ARouter.getInstance().build(RouterPath.MODULE_MINE_FRAGMENT).navigation() as Fragment)
        fragmentAdapter = MyFragmentAdapter(this, list)
        binding.vp.adapter = fragmentAdapter

        val data: ArrayList<CustomTabEntity> = ArrayList()
        data.add(MyTab("首页", R.drawable.home_selected, R.drawable.home_un_selected))
        data.add(MyTab("服务", R.drawable.service_selected, R.drawable.service_un_selected))
        data.add(MyTab("消息", R.drawable.msg_selected, R.drawable.msg_un_selected))
        data.add(MyTab("通知", R.drawable.notice_selected, R.drawable.notice_un_selected))
        data.add(MyTab("我的", R.drawable.mine_selected, R.drawable.mine_un_selected))
        binding.ctl.setTabData(data)
        binding.ctl.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                binding.vp.currentItem = position
            }

            override fun onTabReselect(position: Int) {}
        })
        binding.vp.registerOnPageChangeCallback(object : OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                binding.ctl.currentTab = position
            }
        })
        binding.vp.isUserInputEnabled = false
    }

    override fun initData() {

    }

}